import Taro from '@tarojs/taro';
import { setGlobalData, getAppData } from '@utils/tools'
// import tools from '@common/utils/tools';
// import { setGlobalData } from '@store/app-data';
/**
 * 获取屏幕顶部信息
 * @param appInstance
 */
export function getScreenInfo() {
    const statusBarHeight = getAppData().systemInfo?.statusBarHeight || 0; // 状态栏高度
    const screenWidth = getAppData().systemInfo?.screenWidth;
    const screenHeight = getAppData().systemInfo?.screenHeight;

    let headerPosi = getAppData().headerPosition; // 胶囊位置信息

    if (!headerPosi || !headerPosi.height) {
        headerPosi = Taro.getMenuButtonBoundingClientRect();
        setGlobalData({
            headerPosition: headerPosi,
        });
    }
    const rightBtnPosition = {
        // 胶囊实际位置，坐标信息不是左上角原点
        height: headerPosi.height,
        width: headerPosi.width,
        top: headerPosi.top - statusBarHeight,
        bottom: headerPosi.bottom - headerPosi.height - statusBarHeight, // 胶囊bottom - 胶囊height - 状态栏height （胶囊实际bottom 为距离导航栏底部的长度）
        right: screenWidth - headerPosi.right, // 屏幕宽度 - 胶囊right
    };

    const navHeight = rightBtnPosition.height + rightBtnPosition.top + rightBtnPosition.bottom + statusBarHeight; // 导航高度;

    return {
        navHeight,
        screenWidth,
        statusBarHeight,
        screenHeight,
        rightBtnPosition,
    };
}